/// 简单封装互斥锁
#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <string>

// 基础互斥锁的封装
namespace MutexModel
{
    class Mutex
    {
    public:
        Mutex()
        {
            pthread_mutex_init(&_Mutex, nullptr);
        }
        ~Mutex()
        {
            pthread_mutex_destroy(&_Mutex);
        }
        void Lock()
        {
            int n = pthread_mutex_lock(&_Mutex);
            (void)n;
        }
        void Unlock()
        {
            int n = pthread_mutex_destroy(&_Mutex);
            (void)n;
        }

    private:
        pthread_mutex_t _Mutex;
    };

    // RAII守卫类
    class LockGuard
    {
    public:
        LockGuard(Mutex& mtx)
        :_mtx(mtx)
        {
            _mtx.Lock();
        }
        ~LockGuard()
        {
            _mtx.Unlock();
        }
    private:
        Mutex &_mtx;
    };
}